package com.exm.collectcodenew.juc.threadlocal;
public class TestThreadLocal {
    // 创建线程变量，Threadlocal 不支持继承性
//    public static ThreadLocal<String> threadLocal = new ThreadLocal<String> ();

    // InheritableThreadLocal支持继承性
    public static ThreadLocal<String> threadLocal = new InheritableThreadLocal<String> ();
    public static void main(String [] args) {
        // (2) 设置线程交量
        threadLocal.set ("hello world");
        // (3 ）启动子线程
        Thread thread= new Thread (new Runnable() {
            public void run () {
                // ( 4 ) 子线程输出线程交量的值
                System.out.println ( "thread :" + threadLocal.get());
                }
            }) ;
            thread.start();
            // (5 ）主线程输出线程变量的值
            System.out.println( "main ：" +threadLocal.get()) ;

    }
}
